package com.ejia.ui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.ejia.pojo.car;
import com.ejia.server.CarServices;

import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.awt.event.ActionEvent;
import java.awt.Toolkit;

public class carBJ extends JFrame {

	private JPanel contentPane;
	private JTextField txtno;
	private JTextField txtnumber;
	private JTextField txtstatu;
	private static ArrayList<car> cars;
	
	
	

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					carBJ frame = new carBJ();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public carBJ() {
		setIconImage(Toolkit.getDefaultToolkit().getImage(carBJ.class.getResource("/com/ejia/photo/客户管理系统.png")));
		setTitle("编辑车辆信息");
		
		cars=CarServices.find();
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 480, 633);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel label = new JLabel("编辑车辆信息");
		label.setHorizontalAlignment(SwingConstants.CENTER);
		label.setFont(new Font("宋体", Font.PLAIN, 42));
		label.setBounds(87, 15, 283, 64);
		contentPane.add(label);
		
		JLabel label_1 = new JLabel("车主:      "+cars.get(CLGL.index).getUserid().getRealname());
		label_1.setFont(new Font("宋体", Font.PLAIN, 32));
		label_1.setBounds(56, 111, 345, 45);
		contentPane.add(label_1);
		
		JLabel label_2 = new JLabel("车牌号");
		label_2.setFont(new Font("宋体", Font.PLAIN, 32));
		label_2.setBounds(56, 198, 118, 45);
		contentPane.add(label_2);
		
		JLabel label_3 = new JLabel("车位号");
		label_3.setFont(new Font("宋体", Font.PLAIN, 32));
		label_3.setBounds(56, 285, 106, 45);
		contentPane.add(label_3);
		
		JLabel label_4 = new JLabel("状态");
		label_4.setFont(new Font("宋体", Font.PLAIN, 32));
		label_4.setBounds(56, 372, 90, 45);
		contentPane.add(label_4);
		
		txtno = new JTextField();
		txtno.setFont(new Font("宋体", Font.PLAIN, 24));
		txtno.setText(cars.get(CLGL.index).getCarno());
		txtno.setColumns(10);
		txtno.setBounds(202, 212, 199, 27);
		contentPane.add(txtno);
		
		txtnumber = new JTextField();
		txtnumber.setFont(new Font("宋体", Font.PLAIN, 24));
		txtnumber.setText(cars.get(CLGL.index).getCarnumber());
		txtnumber.setColumns(10);
		txtnumber.setBounds(202, 299, 199, 27);
		contentPane.add(txtnumber);
		
		txtstatu = new JTextField();
		txtstatu.setFont(new Font("宋体", Font.PLAIN, 24));
		txtstatu.setText(cars.get(CLGL.index).getStatu());
		txtstatu.setColumns(10);
		txtstatu.setBounds(202, 386, 199, 27);
		contentPane.add(txtstatu);
		
		JButton button = new JButton("修改");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String no=txtno.getText();
				String number=txtnumber.getText();
				String statu=txtstatu.getText();
				if (no.equals("")||number.equals("")||statu.equals("")) {
					JOptionPane.showMessageDialog(null, "请输入完整数据");
				}else {
					if (CarServices.update(no, number, statu, cars.get(CLGL.index).getCarno())) {
						JOptionPane.showMessageDialog(null, "修改成功");
						new CLGL().setVisible(true);
						dispose();
					}else {
						JOptionPane.showMessageDialog(null, "修改失败");
					}
				}
				
			
			}
		});
		button.setFont(new Font("宋体", Font.PLAIN, 42));
		button.setBounds(70, 469, 123, 73);
		contentPane.add(button);
		
		JButton button_1 = new JButton("取消");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				new CLGL().setVisible(true);
				dispose();
				
			}
		});
		button_1.setFont(new Font("宋体", Font.PLAIN, 42));
		button_1.setBounds(263, 469, 123, 73);
		contentPane.add(button_1);
		
		setLocationRelativeTo(null);
	}
}
